package com.cainiao.controller;

import com.cainiao.pojo.Emp;
import com.cainiao.pojo.EmpQueryParam;
import com.cainiao.pojo.PageBean;
import com.cainiao.pojo.Result;
import com.cainiao.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result page(EmpQueryParam empQueryParam){
        PageBean emp = empService.page(empQueryParam);
        return Result.success(emp);
    }

    @PostMapping
    public Result add(@RequestBody Emp emp){
        empService.add(emp);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list(){
        return Result.success(empService.findEmps());
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        empService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        return Result.success(empService.findById(id));
    }

    @PutMapping
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();
    }
}
